require('dotenv').config();
const Koa = require('koa');
const bodyParser = require('koa-bodyparser');
const router = require('./src/routes');
const { sequelize } = require('./src/models');

const syncMode = process.env.SYNC_MODE === 'true';
const app = new Koa();

app.use(bodyParser());
app.use(router.routes()).use(router.allowedMethods());



const startServer = async () => {
  try {
    // if (syncMode) {
    //   await sequelize.sync({ alter: true });
    //   console.log('数据库同步完成');
    // } else {
    //   await sequelize.sync();
    //   console.log('数据库同步（无更改）完成');
    // }

    app.listen(3000, () => {
      console.log('✅ 服务已启动：http://localhost:3000');
    });

  } catch (error) {
    console.error('❌ 数据库连接或同步失败:', error);
  }
};

startServer();
